package hy.example.notifyexample;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

	EditText et;
	Button notify;
	NotificationManager nm;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		et = (EditText) findViewById(R.id.editText1);
		notify = (Button) findViewById(R.id.button1);
		nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

		notify.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
				setNotification();
			}
		});
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		et.setText(intent.getExtras().getString("Value"));
		finish();
	}

	private void setNotification() {
		Intent intent = new Intent(this,TestActivity.class);
		intent.putExtra("Value", "Notification Cancelled");
		PendingIntent pIntent = PendingIntent.getActivity(this, 1, intent,
				PendingIntent.FLAG_UPDATE_CURRENT);
		Notification notification=new Notification(android.R.drawable.ic_dialog_info, "生成了一个提醒", System.currentTimeMillis());
		notification.setLatestEventInfo(this, "生成了一个提醒", "点击以向Activity传递值", pIntent);
		notification.iconLevel=5;
		notification.deleteIntent=pIntent;
		nm.notify(1, notification);
	}

}
